package com.engineering.elink.dao;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.engineering.elink.co.CommentCo;
import com.engineering.elink.co.BaseCo;
import com.engineering.elink.domain.Comment;

public interface CommentMapper {
    int deleteByPrimaryKey(Integer commentId);

    int insert(Comment record);

    int insertSelective(Comment record);

    Comment selectByPrimaryKey(Integer commentId);

    int updateByPrimaryKeySelective(Comment record);

    int updateByPrimaryKey(Comment record);

	Comment select(@Param("userId")String userId, @Param("fkId")String fkId);

	List<Comment> selectTopCommentsByFileId(@Param("co")CommentCo co);

	int selectTopCommentsCount(@Param("co")CommentCo co);

	List<Comment> selectAllCommentsByTopId(@Param("bc")BaseCo bc, @Param("topId")int topId,@Param("type")int type,
			@Param("startTime")Date startTime,@Param("endTime")Date endTime);

	int selectCount(@Param("bc")BaseCo bc, @Param("topId")int topId,
			@Param("startTime")Date startTime,@Param("endTime")Date endTime);	
	
	Map<String, Object> getEvaluateById(@Param("fkId")String fkId,@Param("startTime")Date startTime,
			@Param("endTime")Date endTime,@Param("type")int type);

	List<Map<String, Object>> getRecentComment(@Param("count")int count);

	@Select("select ifnull(max(comment_id),0) from comment")
	int selectMaxCommentId();
	
	@Select("select  count(1) from comment c where c.fk_id=#{fkId} and c.user_id=#{userId} and c.by_user_id =#{byUserId} and c.type=#{type}")
	int selectDistinctCount(@Param("fkId")String fkId,@Param("userId")String userId,@Param("byUserId")String byUserId,@Param("type")int type);
	
	@Select(" select  count(1) from comment c where c.fk_id=#{fkId} and c.user_id=#{userId} and c.by_user_id =#{byUserId} and c.type=#{type} and top_id >0")
	int selectReplyCount(@Param("fkId")String fkId,@Param("userId")String userId,@Param("byUserId")String byUserId,@Param("type")int type);

	
	List<Map<String, Object>>  selectCommentForMe(@Param("bc")BaseCo bc, @Param("userId")String userId);

	int  selectCountCommentForMe(@Param("userId")String userId);
	
	List<Map<String, Object>>  selectMyComment(@Param("bc")BaseCo bc, @Param("userId")String userId);

	int  selectCountMyComment(@Param("userId")String userId);

	int delComment(@Param("userId")String userId, @Param("type")int type);
	
    Comment selectInfo(@Param("commentId")Integer commentId,@Param("userId")String userId);
}